package com.example.administrator.newjiajiesong.main.activity;

import android.support.annotation.NonNull;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;

import com.example.administrator.newjiajiesong.R;
import com.example.administrator.newjiajiesong.base.BaseTreeActivity;
import com.example.administrator.newjiajiesong.main.activity.mvp.contract.LoginContract;
import com.example.administrator.newjiajiesong.main.activity.mvp.presenter.LoginPresenterImpl;
import com.example.administrator.newjiajiesong.main.my.entity.TreeUserEntity;
import com.example.administrator.newjiajiesong.widget.ClearEditText;

/**
 * LoginActivity
 * (๑• . •๑)
 * 类描述:登录页面
 * Created by LeiXiaoXing on 2017/3/14 14:37
 */

public class LoginActivity extends BaseTreeActivity<LoginContract.View, LoginPresenterImpl> implements LoginContract.View {

    private ClearEditText mCetphone;
    private ClearEditText mCetpassword;
    private EditText mEtcode;
    private Button mBtnsendcode;
    private CheckBox mCheckBox;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_login;
    }

    @Override
    protected void initView() {
        initStyle(true);

        mBtnsendcode = (Button) findViewById(R.id.btn_send_code);
        mEtcode = (EditText) findViewById(R.id.et_code);
        mCetpassword = (ClearEditText) findViewById(R.id.cet_password);
        mCetphone = (ClearEditText) findViewById(R.id.cet_phone);
        mCheckBox = (CheckBox) findViewById(R.id.cb_save);
    }

    @Override
    protected void initData() {
        getPresenter().initData();
    }

    @Override
    protected void initEvent() {
        mBtnsendcode.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //发送验证码
                getPresenter().sendCode();
            }
        });
        //登录
        findViewById(R.id.btn_login).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getPresenter().login();
            }
        });
        //忘记密码
        findViewById(R.id.tv_forget_pw).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(FindPasswordActivity.class);
            }
        });
        //注册
        findViewById(R.id.tv_go_register).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(RegisterActivity.class);
            }
        });
        //微信登录
        findViewById(R.id.iv_login_weichat).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getPresenter().weChatLogin();
            }
        });
    }

    @NonNull
    @Override
    public LoginPresenterImpl createPresenter() {
        return new LoginPresenterImpl();
    }

    @Override
    public String getMobile() {
        return mCetphone.getText().toString();
    }

    @Override
    public void setMobile(String mobile) {
        mCetphone.setText(mobile);
    }

    @Override
    public String getPassWord() {
        return mCetpassword.getText().toString();
    }

    @Override
    public void setPassWord(String passWord) {
        mCetpassword.setText(passWord);
    }

    @Override
    public String getCode() {
        return mEtcode.getText().toString();
    }

    @Override
    public boolean isSavePassword() {
        return mCheckBox.isChecked();
    }


    @Override
    public void setCodeBtnEnable(boolean enable) {
        mBtnsendcode.setEnabled(enable);
    }

    @Override
    public void setCodeBtnText(String msg) {
        mBtnsendcode.setText(msg);
    }


    /**
     * 如果微信登录检测到手机号为空跳去修改手机页面
     * @param isBindPhone
     */
    @Override
    public void goBindPhone(boolean isBindPhone) {
       /* if (!isBindPhone){
            startActivity(EditPhoneNumberActivity.class);
            finish();
        }*/
    }

    @Override
    public void goWxBindPhone(boolean isBindPhone, TreeUserEntity treeUserEntity) {

    }

}
